package health.lm.com.mine.present;

import com.alibaba.android.arouter.launcher.ARouter;

import java.io.File;
import health.lm.com.component_base.base.mvp.contract.XPresent;
import health.lm.com.mine.activity.SettingActivity;
import health.lm.com.mine.entity.SettingBean;
import health.lm.com.mine.entity.UploadHeadBean;
import health.lm.com.mine.model.MineModel;
import health.lm.com.network.EasyHttp;
import health.lm.com.network.callback.SimpleCallBack;
import health.lm.com.network.exception.ApiException;
import health.lm.com.router.ARouterConstant;

/**
 * 设置
 */
public class SettingPresenter extends XPresent<SettingActivity>{
    private String headUrl;
    public void settingData(){
        MineModel.getInstance().setting(new SimpleCallBack<SettingBean>() {
            @Override
            public void onSuccess(SettingBean settingBean) {
                if (hasV()){
                    getV().getSettingData(settingBean);
                }
            }

        });
    }
    public void changeHead() {
        MineModel.getInstance().changeHeadImage(headUrl, new SimpleCallBack<Object>() {
            @Override
            public void onSuccess(Object o) {
                if (hasV()){
                    getV().changeHeadSuccess(headUrl);
                }
            }
        });
    }

    public void uploadHead(File file) {
        MineModel.getInstance().uploadImage(file, new SimpleCallBack<UploadHeadBean>() {
            @Override
            public void onSuccess(UploadHeadBean bean) {
                EasyHttp.getInstance().setEncrypt(true);
                if (bean.getList().size() >0) {
                    headUrl = bean.getList().get(0);
                }
                changeHead();
            }

            @Override
            public void onError(ApiException e) {
                super.onError(e);
                EasyHttp.getInstance().setEncrypt(true);
            }
        });
    }

    public void loginOut() {
        MineModel.getInstance().loginOut(new SimpleCallBack<Object>() {
            @Override
            public void onSuccess(Object o) {
                if(hasV()){
                    getV().loginOutSuccess();
                }
            }
        });
    }
}
